Skip to content

fix: only count gateway as used IP when it falls within the CIDR range#126

Merged
v0l merged 1 commit intomasterfrom
fix/gateway-outside-cidr-ip-allocation
Apr 26, 2026
Merged

fix: only count gateway as used IP when it falls within the CIDR range#126
v0l merged 1 commit intomasterfrom
fix/gateway-outside-cidr-ip-allocation

Conversation

@v0l
Copy link
Copy Markdown
Contributor

@v0l v0l commented Apr 26, 2026

Summary

  • In pick_ip_from_range, the gateway IP was unconditionally inserted into the used-IP HashSet, even when the gateway fell outside the allocation CIDR
  • This inflated ips.len() and triggered the early-exit ips.len() >= size check, falsely reporting the range as full when free IPs remained
  • Example: range 15.235.3.224/28 (16 IPs) with gateway 148.113.164.254 (outside CIDR), 15 assigned IPs → .237 was free but the range was reported as full

Fix

  • Only insert the gateway into the used set when range_cidr.contains(gateway.ip()), consistent with how count_available_ips already handles this case
  • Added regression test test_pick_ip_gateway_outside_range_not_full

When the gateway IP is outside the allocation CIDR (e.g. gateway
148.113.164.254 for range 15.235.3.224/28), it was still unconditionally
added to the used-IP set. This inflated ips.len() and triggered the
early-exit ips.len() >= size check, falsely reporting the range as full
when free IPs remained.
@v0l v0l merged commit ec4bf95 into master Apr 26, 2026
6 checks passed
@v0l v0l deleted the fix/gateway-outside-cidr-ip-allocation branch April 26, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant